package com.cqgc.controller;

import com.cqgc.pojo.entity.Result;
import com.cqgc.utils.AliOssUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

/**
 * @author : 是你
 * @time : 2024/3/20 16:40
 */
@RestController
@RequestMapping("/file")
@Api(tags = "文件上传")
public class FileUploadController {

    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public Result upload(MultipartFile file) throws IOException {
        System.out.println("hh");
        String originalFilename = file.getOriginalFilename();
        String filename = UUID.randomUUID().toString() + originalFilename.substring(originalFilename.lastIndexOf("."));
        String url = AliOssUtil.uploadFile(filename, file.getInputStream());
        return Result.success(url);
    }
}
